<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="5">
          <el-form ref="form" :model="form">
            <el-form-item label="选择日期：">
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 150px"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="5">
          <el-form ref="form" :model="form">
            <el-form-item label="分组：">
              <el-select v-model="teamValue" placeholder style="width: 150px">
                <el-option
                  v-for="item in teamList"
                  :key="item.CLIENT_NO"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="5">
          <el-form ref="form" :model="form">
            <el-form-item label="姓名：">
              <el-input
                style="width: 150px"
                v-model="form.name"
                placeholder="请输入巡查员姓名"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="3">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
    >
      <el-table-column
        prop="巡查员"
        label="巡查员"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="分组"
        label="分组"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="巡查区域"
        label="巡查区域"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="进区域时间"
        label="进区域时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="出区域时间"
        label="出区域时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="巡查时长"
        label="巡查时长"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="巡查该区域总时长"
        label="巡查该区域总时长"
        align="center"
      ></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      loading: false,
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        name: '',
        radioData: '日',
        valueDay: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: ''
      },
      teamList: [],
      teamValue: '',
      tableData: [],
      originalData: []

    }
  },
  created () {
    this.getTeamList()
    this.getlistdata()
  },
  methods: {
    async getTeamList () {
      // var url = 'Worker/GetGroupList?ClientNo=' + localStorage.getItem('CLIENT_NO') // zxdata
      var url = 'DataListCompany/GetCleanerGroupListApi?ClientNo=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.teamList = data
      this.teamValue = this.teamList[0].CLIENT_NO
    },
    async getlistdata () {
      this.currentPage = 1;
      this.loading = true
      var url = 'Worker/GetWorkerCheckInfoDetailYL?ClientNo=' + this.teamValue + '&Date=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.originalData = data
      this.personQuery()
      this.loading = false
    },
    personQuery () {
      this.tableData = this.originalData
      // const { name, client } = this.person
      if (this.form.name) this.tableData = this.tableData.filter(item => item.巡查员.includes(this.form.name))
      // if (this.teamValue != '全部') this.tableData = this.tableData.filter(item => this.teamValue == item.Town)
    },
    // 导出Excel
    exportExcel () {
      let excelName = '巡查作业详情'
      //巡查员，分组，巡查区域，进区域时间，出区域时间，巡查时长，巡查该区域总时长
      const tHeader = ['巡查员', '分组', '巡查区域', '进区域时间', '出区域时间', '巡查时长', '巡查该区域总时长']
      const filterVal = ['巡查员', '分组', '巡查区域', '进区域时间', '出区域时间', '巡查时长', '巡查该区域总时长']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>